//
// Created by Win on 2017/1/19.
//
#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frbyte_buffer.h"

#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_cunit.h"
#include "apmtest_comm.h"
#include "frhessian.h"

extern int frhessian_get_double(Frbyte_Packet *p_st_data, Frreport_body_data *p_st_body_data, char *p_name);

static int __suite_init(void)
{
    
    return 0;
}

static int __suite_cleanup(void)
{
    
    return 0;
}


static void __case1(void)
{
    
    int i_ret = 0;
    
    i_ret = frhessian_get_double(NULL, NULL, NULL);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    
    return;
    
}


static void __case2(void)
{
    
    int i_ret = 0;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;
    Frbyte_Packet *p_st_data = NULL;
    
    i_ret = apmtest_create_ct(&p_st_conn, NULL, (char *)"192.168.0.1", (char *)"192.168.0.35", 5460, 5672);
    p_st_body_data = frreport_body_new_l7 (p_st_conn);
    
    p_st_data = bytebuff_creat();
    
    bytebuff_add(p_st_data, (char *)"\x40\x14\x00\x00\x00\x00\x00\x00", 8);
    
    i_ret = frhessian_get_double(p_st_data, p_st_body_data, (char *)"http.hessian.arg");
    
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    
    frreport_body_free(&p_st_body_data);
    apmtest_destroy_ct(&p_st_conn);
    bytebuff_free(&p_st_data);
    
    return;
    
}


int add_suite_frhessian_get_double(void)
{
    CU_pSuite pSuite = NULL;
    
    if ((pSuite = CU_add_suite("frhessian.c frhessian_get_double()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;
    
    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    
    
    return FR_SUCC;
    
}